﻿<%@ Page Language="C#" AutoEventWireup="true" Theme="Default" CodeBehind="ZhuGuanBMXX.aspx.cs" Inherits="Web.Pages.QuShui.DiXiaS._1.JiChuXX.ZhuGuanBMXX" %>


<%@ Register Assembly="DevExpress.Web.v15.2, Version=15.2.9.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web" TagPrefix="dx" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script src="/JS/AddEditCancel.js"></script>
    <script src="/JS/jquery.js"></script>
    <link href="/css/inputBgColor.css" rel="stylesheet" />
    <script type="text/javascript">
        function keyEnter(index) {
            if (event.keyCode != 13)
            {
                return;
            }
            index++;
            switch(index)
            {
                case 0: txtBianHao.Focus();
                    break;
                case 1: txtMingCheng.Focus();
                    break;
                case 2: txtYouBian.Focus();
                    break;
                case 3: txtDiZ.Focus();
                    break;
                case 4: txtLianXiR.Focus();
                    break;

                case 5: txtLianXiBM.Focus();
                    break;
                case 6: txtLianXiDH.Focus();
                    break;
                case 7: cmYeWuY.Focus();
                    break;
                case 8: txtKaiHuHM.Focus();
                    break;
                case 9: txtKaiHuYH.Focus();
                    break;
                case 10: txtKaiHuZH.Focus();
                    break;
                case 11: txtBeiZhu.Focus();
                    break;
                case 12: btnSave.Focus();
                    break;
            }
        }
    </script>
    <script type="text/javascript">
        function ClearInfo() {
            hdCollection.Set("ID", -1);
            txtBianHao.SetText("");
            txtMingCheng.SetText("");
            txtDiZ.SetText("");
            
          
            txtYouBian.SetText("");
            txtLianXiDH.SetText("");
            txtLianXiBM.SetText("");
            txtLianXiR.SetText("");
            txtBeiZhu.SetText("");

            cmYeWuY.SetText("");

            txtKaiHuHM.SetText("");
            txtKaiHuYH.SetText("");
            txtKaiHuZH.SetText("");
            chkTuoSHou.SetChecked(false);
        }

        function SetEnabled(enabled) {
            txtBianHao.SetEnabled(enabled);
            txtMingCheng.SetEnabled(enabled);
            txtDiZ.SetEnabled(enabled);
           
            txtYouBian.SetEnabled(enabled);
            txtLianXiDH.SetEnabled(enabled);
            txtLianXiBM.SetEnabled(enabled);
            txtLianXiR.SetEnabled(enabled);
            txtBeiZhu.SetEnabled(enabled);

            cmYeWuY.SetEnabled(enabled);

            txtKaiHuHM.SetEnabled(enabled);
            txtKaiHuYH.SetEnabled(enabled);
            txtKaiHuZH.SetEnabled(enabled);
            //chkTuoSHou.SetEnabled(enabled);
        }

        function display(op) {
            
            if (gvList.GetFocusedRowIndex() == -1) {
               
            }
            hdCollection.Set("op", op);
            if (hdCollection.Get("op") == "add" || hdCollection.Get("op") == "edit") {
                btnAdd.SetVisible(false);
                btnEdit.SetVisible(false);
                btnDel.SetVisible(false);
                btnSave.SetVisible(true);
                btnCancel.SetVisible(true);
                SetEnabled(true);
                listCover(true, "divList");
            }
            else if (hdCollection.Get("op") == "init") {
                btnAdd.SetVisible(true);
                btnEdit.SetVisible(true);
                btnDel.SetVisible(true);
                btnSave.SetVisible(false);
                btnCancel.SetVisible(false);
                SetEnabled(false);
                listCover(false, "divList");
            }
            
            if (op == "add") {
                
                ClearInfo();
                txtBianHao.Focus();
            }
            else if (op == "edit") {
                txtBianHao.SetEnabled(false);
                txtMingCheng.Focus();
            }
            else if (op == "init") {
                txtBianHao.SetEnabled(false);
                hdCollection.Set("ID", gvList.GetRowKey(gvList.GetFocusedRowIndex()));
                ASPxCallback1.PerformCallback("setinfo");
            }
        }


        function search() {
            if (conBH.GetText() == "") {
                return;
            }
            ASPxCallback1.PerformCallback("search");
        }

        function rowClick() {
            var id = -1;
            if (gvList.GetFocusedRowIndex() != -1) {
                id = gvList.GetRowKey(gvList.GetFocusedRowIndex());
                hdCollection.Set("ID", id);
                loadpanel1.Show();
                ASPxCallback1.PerformCallback("setinfo");

            }
            else {
                ClearInfo();
                hdCollection.Set("ID", id);
            }
        }

        function endback() {
            
            rowClick();
        }

        function bind() {
            gvList.PerformCallback();
        }

        function save() {
            //保存前先验证
            //var m = CheckSaveData();
            // alert(m);
            //debugger;
            //alert(chkTuoSHou.GetChecked());
            //var ck = chkTuoSHou.GetChecked();
            if (txtBianHao.GetText() == "") {
                alert("编号不能为空");
                txtBianHao.Focus();
                
            }
            else if (txtMingCheng.GetText() == "") {
                alert("名称不能为空");
                txtMingCheng.Focus();
                
            }
            else if (txtYouBian.GetText() == "") {
                alert("邮编不能为空");
                txtYouBian.Focus();
                
            }
            else if (txtDiZ.GetText() == "") {
                alert("地址不能为空");
                txtDiZ.Focus();
                
            }
            else if (txtLianXiR.GetText() == "") {
                alert("联系人不能为空");
                txtLianXiR.Focus();
               
            }
            else if (txtLianXiBM.GetText() == "") {
                alert("联系部门不能为空");
                txtLianXiBM.Focus();
               
            }
            else if (txtLianXiDH.GetText() == "") {
                alert("联系电话不能为空");
                txtLianXiDH.Focus();
                
            }
            else if (cmYeWuY.GetText() == "") {
                alert("业务员不能为空");
                cmYeWuY.Focus();
               
            }
            else if (chkTuoSHou.GetChecked()) {
                if (txtKaiHuHM.GetText() == "") {
                    alert("开户户名不能为空");
                    txtKaiHuHM.Focus();
                   
                }
                else if (txtKaiHuYH.GetText() == "") {
                    alert("开户银行不能为空");
                    txtKaiHuYH.Focus();
                   
                }
                else if (txtKaiHuZH.GetText() == "") {
                    alert("开户账号不能为空");
                    txtKaiHuZH.Focus();
                   
                }
            }
            else {
                
                ASPxCallback1.PerformCallback("save");
            }
           
        }

      


        function del() {
            if (gvList.GetFocusedRowIndex() == -1) {
                alert("未选择主管部门信息。");
                return;
            }
            ASPxCallback1.PerformCallback("deleteValidate");
        }

        function ASPxCallback1Complete(rs) {
            var arr = rs.split('|');
            var type = arr[0];
            var state = arr[1];
            loadpanel1.Hide();
            if (state != "0") {
                alert(arr[2]);

            }
            else {
                if (type == "save") {
                    alert(arr[2]);
                    txtBianHao.Focus();
                    display("init");
                    bind();
                    
                    
                }
                else if (type == "deleteValidate") {
                    if (confirm("当前主管部门没有用户使用,你确定要删除吗？")) {
                        ASPxCallback1.PerformCallback("delete");
                    }
                }
                else if (type == "delete") {
                    alert(arr[2]);
                    ClearInfo();
                    gvList.PerformCallback();
                    gvList.SetFocusedRowIndex = 0;
                }
                else if (type == "search") {
                    gvList.SetFocusedRowIndex(arr[2]);
                    gvList.MakeRowVisible(arr[2]);
                }
                else if (type == "setinfo") {
                   
                    txtBianHao.SetText(arr[2]);
                    txtMingCheng.SetText(arr[3]);
                    txtYouBian.SetText(arr[4]);
                    txtDiZ.SetText(arr[5]);
                    txtLianXiR.SetText(arr[6]);
                    txtLianXiBM.SetText(arr[7]);
                    txtLianXiDH.SetText(arr[8]);
                    cmYeWuY.SetValue(arr[9]);
                    
                    txtKaiHuHM.SetText(arr[10]);
                    txtKaiHuYH.SetText(arr[11]);
                    txtKaiHuZH.SetText(arr[12]);
                   
                    txtBeiZhu.SetText(arr[13]);
                    if (arr[14] == 1) {
                        chkTuoSHou.SetChecked(true);
                    }
                    else {
                        chkTuoSHou.SetChecked(false);
                    }
                }
            }
        }
    </script>
</head>
<body style="overflow: hidden">
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <div class="tabletitle1" align="center">
            主管部门信息
        </div>
        <div style="display: none;">
            <dx:ASPxHiddenField ID="hdCollection" ClientInstanceName="hdCollection" runat="server"></dx:ASPxHiddenField>
            <dx:ASPxButton ID="btnActPerform" ClientInstanceName="btnActPerform" runat="server" Text="ASPxButton"></dx:ASPxButton>
            <dx:ASPxCallback ID="ASPxCallback1" ClientInstanceName="ASPxCallback1" runat="server" OnCallback="ASPxCallback1_Callback" ClientSideEvents-CallbackComplete="function(s,e){ASPxCallback1Complete(e.result);}"></dx:ASPxCallback>
        </div>
        <div style="width: 100%">
            <div style="float: left; width: 30%; min-width:150px" id="divList">

                <asp:UpdatePanel runat="server" ID="UpdatePanel1">
                    <ContentTemplate>
                        <dx:ASPxGridView ID="gvList" ClientInstanceName="gvList" runat="server" AutoGenerateColumns="False" KeyFieldName="ID" Theme="Aqua1"
                            Width="100%" OnCustomCallback="gvList_CustomCallback" EnableCallBacks="true">
                            <Columns>
                                <dx:GridViewDataTextColumn FieldName="S_BUMENBH" Caption="编号" Width="15%">
                                </dx:GridViewDataTextColumn>
                                <dx:GridViewDataTextColumn FieldName="S_BUMENMC" Caption="名称" Width="85%">
                                </dx:GridViewDataTextColumn>
                              
                            </Columns>
                            <SettingsBehavior AllowFocusedRow="True" ColumnResizeMode="Control"  ProcessFocusedRowChangedOnServer="false" />
                            <Settings VerticalScrollableHeight="440" VerticalScrollBarMode="Auto" />
                            <ClientSideEvents FocusedRowChanged="function(s,e){rowClick();}"  EndCallback="endback" Init="function(s,e){AdjustSize(100,gvList);}" />
                        </dx:ASPxGridView>
                    </ContentTemplate>
                </asp:UpdatePanel>
                <dx:ASPxLoadingPanel ID="ASPxLoadingPanel1" ClientInstanceName="loadpanel1" runat="server" ContainerElementID="gvList" Modal="true" Theme="Metropolis" Text=""></dx:ASPxLoadingPanel>
                <dx:ASPxLoadingPanel ID="ASPxLoadingPanel2" ClientInstanceName="loadpanel2" runat="server" Text="加载中..."></dx:ASPxLoadingPanel>
            </div>
            <div style="float: left; width: 1%;">&nbsp;</div>
            <div style="float: left; width: 69%; min-width:400px; overflow: auto;">
                <table style="width: 100%" id="GridViewContentTable" runat="server">
                    <tr>
                        <td align="right" style="width: 80px; white-space: nowrap;">编号：
                        </td>
                        <td >
                            <dx:ASPxTextBox ID="txtBianHao" ClientInstanceName="txtBianHao"  ClientEnabled="false" runat="server" Width="100%" MaxLength="5">
                                <ClientSideEvents KeyUp="function(s,e){inputNum(s);keyEnter(0);}" />
                            </dx:ASPxTextBox>
                        </td>
                        <td ></td>
                        <td ></td>
                    </tr>
                    <tr>
                        <td align="right">名称：
                        </td>
                        <td colspan="3">
                            <dx:ASPxTextBox ID="txtMingCheng" ClientInstanceName="txtMingCheng" ClientEnabled="false" runat="server" Text="" Width="100%" MaxLength="50">

                                <ClientSideEvents KeyPress="function(s,e){keyEnter(1);}" />
                            </dx:ASPxTextBox>
                        </td>
                    </tr>
                    <tr>
                       <td align="right">邮编：
                        </td>
                        <td colspan="3">
                            <dx:ASPxTextBox ID="txtYouBian" ClientInstanceName="txtYouBian" ClientEnabled="false" runat="server" Width="100%" MaxLength="6">
                                <ClientSideEvents KeyPress="function(s,e){keyEnter(2);}" />
                            </dx:ASPxTextBox>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">地址：
                        </td>
                        <td colspan="3">
                            <dx:ASPxTextBox ID="txtDiZ" ClientInstanceName="txtDiZ" ClientEnabled="false" runat="server" Width="100%" MaxLength="100">
                                <ClientSideEvents KeyPress="function(s,e){keyEnter(3);}" />
                            </dx:ASPxTextBox>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">联系人：
                        </td>
                        <td>
                            <dx:ASPxTextBox ID="txtLianXiR" ClientInstanceName="txtLianXiR" ClientEnabled="false" runat="server" Width="100%" MaxLength="30">
                                <ClientSideEvents KeyPress="function(s,e){keyEnter(4);}" />
                            </dx:ASPxTextBox>
                        </td>
                        <td align="right">联系部门：
                        </td>
                        <td>
                            <dx:ASPxTextBox ID="txtLianXiBM" ClientInstanceName="txtLianXiBM" ClientEnabled="false" runat="server" Width="100%" MaxLength="30">
                                <ClientSideEvents KeyPress="function(s,e){keyEnter(5);}" />
                            </dx:ASPxTextBox>
                        </td>
                    </tr>
                    <tr>
                       
                        <td align="right" style="white-space: nowrap;">联系电话：
                        </td>
                        <td>
                            <dx:ASPxTextBox ID="txtLianXiDH" ClientInstanceName="txtLianXiDH" ClientEnabled="false" runat="server" Width="100%" MaxLength="50">
                                <ClientSideEvents KeyPress="function(s,e){keyEnter(6);}" />
                            </dx:ASPxTextBox>
                        </td>
                        <td align="right">
                            业务员：
                        </td>
                        <td>
                            <dx:ASPxComboBox ID="cmYeWuY" ClientInstanceName="cmYeWuY" runat="server" ClientEnabled="false" ValueType="System.String">
                                <Items>
                                </Items>
                                 <ClientSideEvents KeyPress="function(s,e){keyEnter(7);}" />
                            </dx:ASPxComboBox>
                        </td>
                    </tr>
                    <tr>
                        <td></td>
                        <td colspan="3">
                            <dx:ASPxCheckBox ID="chkTuoSHou" ClientInstanceName="chkTuoSHou" Text="是否托收" ClientEnabled="false" runat="server"  Checked="true" >                               
                            </dx:ASPxCheckBox>
                        </td>
                       
                    </tr>
                   <tr>
                        <td align="right">
                            开户户名：
                        </td>
                       <td colspan="3">
                           <dx:ASPxTextBox ID="txtKaiHuHM" ClientInstanceName="txtKaiHuHM" runat="server" ClientEnabled="false" Width="100%">
                                <ClientSideEvents KeyPress="function(s,e){keyEnter(8);}" />
                           </dx:ASPxTextBox>
                       </td>
                   </tr>
                     <tr>
                        <td align="right">
                            开户银行：
                        </td>
                       <td colspan="3">
                           <dx:ASPxTextBox ID="txtKaiHuYH" ClientInstanceName="txtKaiHuYH"  runat="server" ClientEnabled="false" Width="100%">
                                <ClientSideEvents KeyPress="function(s,e){keyEnter(9);}" />
                           </dx:ASPxTextBox>
                       </td>
                   </tr>
                     <tr>
                        <td align="right">
                            开户账号：
                        </td>
                       <td colspan="3">
                           <dx:ASPxTextBox ID="txtKaiHuZH" ClientInstanceName="txtKaiHuZH" runat="server" ClientEnabled="false" Width="100%">
                                <ClientSideEvents KeyPress="function(s,e){keyEnter(10);}" />
                           </dx:ASPxTextBox>
                       </td>
                   </tr>
                    <tr>
                        <td align="right" valign="top">备注：
                        </td>
                        <td colspan="3">
                            <dx:ASPxMemo ID="txtBeiZhu" ClientInstanceName="txtBeiZhu" ClientEnabled="false" runat="server" Height="100px" Width="100%" MaxLength="120">
                                <ClientSideEvents KeyPress="function(s,e){OnKeyNext(btnSave);}" />
                            </dx:ASPxMemo>
                        </td>
                    </tr>
                </table>
                <div align="right">
                    <hr />
                    <dx:ASPxButton ID="btnAdd" ClientInstanceName="btnAdd" runat="server" Text="添加" AutoPostBack="false" UseSubmitBehavior="false" ClientSideEvents-Click="function(s,e){display('add');}">
                    </dx:ASPxButton>
                    <dx:ASPxButton ID="btnEdit" ClientInstanceName="btnEdit" runat="server" Text="修改" AutoPostBack="false" UseSubmitBehavior="false" ClientSideEvents-Click="function(s,e){display('edit');}">
                    </dx:ASPxButton>
                    <dx:ASPxButton ID="btnDel" ClientInstanceName="btnDel" runat="server" Text="删除" AutoPostBack="false" UseSubmitBehavior="false" ClientSideEvents-Click="function(s,e){del();}">
                    </dx:ASPxButton>
                    <dx:ASPxButton ID="btnSave" ClientInstanceName="btnSave" runat="server" Text="保存" ClientVisible="false" AutoPostBack="false" UseSubmitBehavior="false">
                        <ClientSideEvents Click="function(s, e){save();}" />
                    </dx:ASPxButton>
                    <dx:ASPxButton ID="btnCancel" ClientInstanceName="btnCancel" runat="server" Text="放弃" ClientVisible="false" AutoPostBack="false" UseSubmitBehavior="false" ClientSideEvents-Click="function(s,e){display('init');}">
                    </dx:ASPxButton>
                </div>
            </div>
        </div>
    </form>
</body>
</html>
